package com.eden.websocket.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.eden.common.annotation.Log;
import com.eden.common.enums.BusinessType;
import com.eden.websocket.domain.ChatList;
import com.eden.websocket.service.IChatListService;
import com.eden.common.core.controller.BaseController;
import com.eden.common.core.domain.AjaxResult;
import com.eden.common.utils.poi.ExcelUtil;
import com.eden.common.core.page.TableDataInfo;

/**
 * 聊天消息列Controller
 *
 * @author jiaoyang
 * @date 2021-03-06
 */
@Controller
@RequestMapping("/chatList/chatList")
public class ChatListController extends BaseController
{
    private String prefix = "chatList/chatList";

    @Autowired
    private IChatListService chatListService;

    @RequiresPermissions("chatList:chatList:view")
    @GetMapping()
    public String chatList()
    {
        return prefix + "/chatList";
    }

    /**
     * 查询聊天消息列列表
     */
    @RequiresPermissions("chatList:chatList:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ChatList chatList)
    {
        startPage();
        List<ChatList> list = chatListService.selectChatListList(chatList);
        return getDataTable(list);
    }

    /**
     * 导出聊天消息列列表
     */
    @RequiresPermissions("chatList:chatList:export")
    @Log(title = "聊天消息列", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ChatList chatList)
    {
        List<ChatList> list = chatListService.selectChatListList(chatList);
        ExcelUtil<ChatList> util = new ExcelUtil<ChatList>(ChatList.class);
        return util.exportExcel(list, "chatList");
    }

    /**
     * 新增聊天消息列
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存聊天消息列
     */
    @RequiresPermissions("chatList:chatList:add")
    @Log(title = "聊天消息列", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ChatList chatList)
    {
        return toAjax(chatListService.insertChatList(chatList));
    }

    /**
     * 修改聊天消息列
     */
    @GetMapping("/edit/{chatId}")
    public String edit(@PathVariable("chatId") Long chatId, ModelMap mmap)
    {
        ChatList chatList = chatListService.selectChatListById(chatId);
        mmap.put("chatList", chatList);
        return prefix + "/edit";
    }

    /**
     * 修改保存聊天消息列
     */
    @RequiresPermissions("chatList:chatList:edit")
    @Log(title = "聊天消息列", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ChatList chatList)
    {
        return toAjax(chatListService.updateChatList(chatList));
    }

    /**
     * 删除聊天消息列
     */
    @RequiresPermissions("chatList:chatList:remove")
    @Log(title = "聊天消息列", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(chatListService.deleteChatListByIds(ids));
    }
}